package com.ruoyi.web.dorm.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.dorm.entity.ClassEntity;
import com.ruoyi.web.dorm.entity.vo.ClassStudentVO;
import com.ruoyi.web.dorm.entity.vo.ClassVO;
import com.ruoyi.web.dorm.entity.vo.StudentVO;
import com.ruoyi.web.dorm.mapper.ClassMapper;
import com.ruoyi.web.dorm.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassServiceImpl implements ClassService {
    @Autowired
    private ClassMapper classMapper;

    /**
     * 查询班级信息
     * @param classVO
     * @return
     */
    @Override
    public List<ClassVO> classList(ClassVO classVO) {
        return classMapper.classList(classVO);
    }

    /**
     * 添加班级信息
     * @param classEntity
     * @return
     */
    @Override
    public int addClass(ClassEntity classEntity) {
//        List<ClassEntity> list = classMapper.classList(classEntity);
//        list.forEach(item->{
//            if(item.getClassNum().equals(classEntity.getClassNum())){
//                throw new ServiceException("班级号重复");
//            }
//        });
        String username = SecurityUtils.getLoginUser().getUsername(); //获取修改人的名字 添加进去
        classEntity.setCreateBy(username);
        return classMapper.addClass(classEntity);
    }

    /**
     * 修改班级信息
     * @param classEntity
     * @return
     */
    @Override
    public int updateClass(ClassEntity classEntity) {
//        List<ClassEntity> list = classMapper.classList(classEntity);
//        list.forEach(item->{
//            if(item.getClassNum().equals(classEntity.getClassNum())){
//                throw new ServiceException("班级号重复");
//            }
//        });
        String username = SecurityUtils.getLoginUser().getUsername(); //获取修改人的名字 添加进去
        classEntity.setUpdateBy(username);
        return classMapper.updateClass(classEntity);
    }
//删除
    @Override
    public int delClass(Long id) {
        return classMapper.delClass(id);
    }
//查询班级学生信息
    @Override
    public List<ClassStudentVO> classStudentList(ClassStudentVO classStudentVO) {
        return classMapper.classStudentList(classStudentVO);
    }
}
